package org.jeecg.modules.gongqiang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.gongqiang.entity.*;
import org.jeecg.modules.gongqiang.mapper.AccountVarietyMapper;
import org.jeecg.modules.gongqiang.mapper.NumberPlatformMapper;
import org.jeecg.modules.gongqiang.mapper.OpenPlatformMapper;
import org.jeecg.modules.gongqiang.mapper.OrderIndexArmMapper;
import org.jeecg.modules.gongqiang.service.IAccountVarietyService;
import org.jeecg.modules.gongqiang.service.INumberPlatformService;
import org.jeecg.modules.gongqiang.service.IPlatformAccountService;
import org.jeecg.modules.gongqiang.vo.AccountVarietyParams;
import org.jeecg.modules.gongqiang.vo.NumberPlatformParams;
import org.jeecg.modules.gongqiang.vo.PlatformAccountParams;
import org.jeecg.modules.gongqiang.mapper.OpenPlatformMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 序列号和平台对应关系
 * @Author: jeecg-boot
 * @Date:   2024-10-28
 * @Version: V1.0
 */
@Service
public class NumberPlatformServiceImpl extends ServiceImpl<NumberPlatformMapper, NumberPlatform> implements INumberPlatformService {

    @Autowired
    private IPlatformAccountService platformAccountService;

    @Resource
    private OpenPlatformMapper openPlatformMapper;


    @Override
    public Result<String> deleteAll(String id)
    {
        this.removeById(id);
        LambdaQueryWrapper<PlatformAccount> queryWrapperAccountVariety=new LambdaQueryWrapper<>();
        queryWrapperAccountVariety.eq(PlatformAccount::getNumberPlatformId,id);
        List<PlatformAccount> arrayList=platformAccountService.list(queryWrapperAccountVariety);
        for(PlatformAccount temp:arrayList)
        {
            platformAccountService.deleteAll(temp.getId());
        }

        return Result.OK("删除成功!");
    }

    @Override
    public NumberPlatformParams searhInfos(String id)
    {
        LambdaQueryWrapper< NumberPlatform> queryWrapperNumberPlatform=new LambdaQueryWrapper<>();
        queryWrapperNumberPlatform.eq(NumberPlatform::getSerialNumberId,id);
        List<NumberPlatform> arrayList=this.list(queryWrapperNumberPlatform);
        List< PlatformAccountParams> platformAccountParamsArray=new ArrayList<>();
        for(NumberPlatform temp:arrayList)
        {

            PlatformAccountParams platformAccountParams=new PlatformAccountParams();
            platformAccountParams=platformAccountService.searhInfos(temp.getId());
            OpenPlatform openPlatform=openPlatformMapper.selectById(temp.getOpenPlatformId());
            if(oConvertUtils.isEmpty(openPlatform))
            {
                platformAccountParams.setPlatformName(null);
            }
            else
            {
                platformAccountParams.setPlatformName(openPlatform.getPlatformName());
            }

            platformAccountParamsArray.add(platformAccountParams);
        }
        NumberPlatformParams numberPlatformParams=new NumberPlatformParams();
        numberPlatformParams.setPlatformAccountParamsList(platformAccountParamsArray);
        return numberPlatformParams;
    }
}
